package poject.controller;


import java.io.InputStream;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import poject.pojo.Studentdb;
@Controller
@RequestMapping("/student")
public class studentcontroller {
	@Resource
    private poject.service.StudentdbService StudentdbService;
	
    @RequestMapping("/import")
    public String impotr(HttpServletRequest request) throws Exception {
        //获取上传的文件
        MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext());
        MultipartHttpServletRequest multipart = resolver.resolveMultipart(request);
        
        MultipartFile file = multipart.getFile("file");
        String filename = request.getParameter("filename");
        InputStream in = file.getInputStream();
        System.out.println(filename);
        
        
        //数据插入数据库
        StudentdbService.insertdb(in,file);
        in.close();
        return "forward:../sucess.jsp";
    }
}
